import { useUserStore } from './index'
import { recipient } from '@/api/api'
import { defineStore } from 'pinia'

const userStore = useUserStore() 
export const useRecipientStore = defineStore('recipient', {
	state: () => {
		return {
			trackingNumber: '',
			recipientName: '',
			phoneSuffix: '',
			deliveryAddress: '',
			contactInfo: '',
			remarks: ''
		}
	},
	getters: {
	
	},
	actions: {
	//添加订单
		async setRecipient() {
			const res = await recipient({
				trackingNumber: this.trackingNumber,
				recipientName: userStore.resses.contactName,
				phoneSuffix: userStore.resses.contactPhone.slice(-4),
				deliveryAddress: userStore.resses.tag,
				contactInfo: userStore.resses.contactPhone,
				remarks: this.remarks
			})
			if (res.code === 200) {
				uni.showToast({ title: '发布成功' });
				//关闭半模态
				userStore.isShowModal = false
			} else {
				uni.showToast({ title: res.message, icon: 'none' });
			}
		},
		//清空数据
		empty() {
			this.trackingNumber = ''
			this.recipientName = ''
			this.phoneSuffix = ''
			this.deliveryAddress = ''
			this.contactInfo = ''
			this.remarks = ''
		}
	}
})


// id: "任务ID",
//   trackingNumber: "快递单号",
//   recipientName: "收件人姓名",
//   phoneSuffix: "手机尾号",
//   deliveryAddress: "送货地址",
//   contactInfo: "联系方法",
//   remarks: "备注",
//   orderStatus: "待接单 / 已完成",
//   createTime: "下单时间"